/*
 * Libraries for J2ME (Java mobile) portable devices such as cellular phones.
 * Copyright (c) 2005-2006, Moshe Waisberg. All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Contributors can be contacted by electronic mail via the project Web pages:
 * 
 * https://sourceforge.net/projects/j2melib
 * 
 * http://j2melib.sourceforge.net
 * 
 */

package games;

import javax.microedition.lcdui.Graphics;

//import net.sf.j2me.lcdui.Color;

/**
 * Checkers glyph.
 * 
 * @author Moshe Waisberg
 */
public class CheckersGlyph extends SimpleGlyph {

	/** Is the marker a king piece? */
	public boolean king;

	/**
	 * Constructs a new Checkers glyph.
	 */
	public CheckersGlyph() {
		super();
	}

	public void paint(Graphics g, int x, int y, int width, int height) {
		int min = Math.min(width, height);
		int xCenter = x + (width >> 1) - (1 - (width & 1));
		int yCenter = y + (height >> 1) - (1 - (height & 1));
		int delta = min / 6; //TODO
		int diamOuter = (delta << 2) + (1 - (min & 1));

		int x2 = xCenter - delta;
		int x1 = x2 - delta;
		int y2 = yCenter - delta;
		int y1 = y2 - delta;
		int x3 = xCenter + delta;
		int y3 = yCenter + delta;

		//int borderColor = Color.GRAY.getRGB(); voffk

		g.setStrokeStyle(Graphics.SOLID);

		/* Border. */
		/*if (color == borderColor) borderColor = Color.BLACK.getRGB();
		g.setColor(borderColor);
		g.fillArc(x1 - 1, y1 - 1, diamOuter + 2, diamOuter + 2, 0, 360);*/ //voffk

		/* Outer circle. */
		g.setColor(color);
		g.fillArc(x1, y1, diamOuter, diamOuter, 0, 360);

		if (king) {
			int colorinv = color ^ 0xFFFFFF;
			g.setColor(colorinv);
			g.drawLine(x2 - 1, y2, x3 - 1, y3);
			g.drawLine(x2, y2, x3, y3);
			g.drawLine(x2 + 1, y2, x3 + 1, y3);
			g.drawLine(x2 - 1, y3, x3 - 1, y2);
			g.drawLine(x2, y3, x3, y2);
			g.drawLine(x2 + 1, y3, x3 + 1, y2);

			g.setColor(color);
			g.drawLine(x2 + 1, y2 + 1, x3 - 1, y3 - 1);
			g.drawLine(x2 + 1, y3 - 1, x3 - 1, y2 + 1);
		}
	}
}